package com.youchuang.action.user;

import java.io.InputStream;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.youchuang.action.BaseAction;
import com.youchuang.common.Constant;
import com.youchuang.service.UserService;

/**
 * 图形验证码
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/user")
@ParentPackage("shopping-default")
public class CheckCodeAction extends BaseAction {
	private Logger logger = Logger.getLogger(CheckCodeAction.class.getSimpleName());
	private InputStream imageStream;
	
	@Resource
	private UserService userService;

	@Action(value = "checkCode", results = {
			@Result(name = ActionSupport.SUCCESS, type = "stream", params = { "inputName", "imageStream" }) })
	public String execute() {
		logger.info("method is execute");
		imageStream = userService.getImageCodeStream();
		if (imageStream == null)
			return Constant.ERROR;
		return Constant.SUCCESS;
	}

	public InputStream getImageStream() {
		return imageStream;
	}

	public void setImageStream(InputStream imageStream) {
		this.imageStream = imageStream;
	}

}
